package tij4.concurrent.exercise.ex31;

import java.util.concurrent.ArrayBlockingQueue;

/*
    这是新增加的筷笼,哲学家要从这里拿筷子
 */
public class ChopsticksCage {
    private ArrayBlockingQueue<Chopstick> chopsticks;

    public ChopsticksCage(ArrayBlockingQueue<Chopstick> chopsticks) throws InterruptedException {
        this.chopsticks = chopsticks;
        for (int i = 0; i < chopsticks.size(); i++) {
            chopsticks.put(new Chopstick());
        }
    }

    public Chopstick take() throws InterruptedException {   //从筷笼里拿筷子
        return chopsticks.take();
    }
    public void drop(Chopstick chopstick) throws InterruptedException { //放到筷笼里筷子
        chopsticks.put(chopstick);
    }
}
